package com.ruoyi.calculation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.calculation.domain.ErpCostCalculation;
import com.ruoyi.calculation.service.IErpCostCalculationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成本核算Controller
 * 
 * @author ruoyi
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/calculation/calculation")
public class ErpCostCalculationController extends BaseController
{
    @Autowired
    private IErpCostCalculationService erpCostCalculationService;

    /**
     * 查询成本核算列表
     */
    @PreAuthorize("@ss.hasPermi('calculation:calculation:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpCostCalculation erpCostCalculation)
    {
        startPage();
        List<ErpCostCalculation> list = erpCostCalculationService.selectErpCostCalculationList(erpCostCalculation);
        return getDataTable(list);
    }

    /**
     * 导出成本核算列表
     */
    @PreAuthorize("@ss.hasPermi('calculation:calculation:export')")
    @Log(title = "成本核算", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpCostCalculation erpCostCalculation)
    {
        List<ErpCostCalculation> list = erpCostCalculationService.selectErpCostCalculationList(erpCostCalculation);
        ExcelUtil<ErpCostCalculation> util = new ExcelUtil<ErpCostCalculation>(ErpCostCalculation.class);
        util.exportExcel(response, list, "成本核算数据");
    }

    /**
     * 获取成本核算详细信息
     */
    @PreAuthorize("@ss.hasPermi('calculation:calculation:query')")
    @GetMapping(value = "/{workOrder}")
    public AjaxResult getInfo(@PathVariable("workOrder") String workOrder)
    {
        return success(erpCostCalculationService.selectErpCostCalculationByWorkOrder(workOrder));
    }

    /**
     * 新增成本核算
     */
    @PreAuthorize("@ss.hasPermi('calculation:calculation:add')")
    @Log(title = "成本核算", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpCostCalculation erpCostCalculation)
    {
        return toAjax(erpCostCalculationService.insertErpCostCalculation(erpCostCalculation));
    }

    /**
     * 修改成本核算
     */
    @PreAuthorize("@ss.hasPermi('calculation:calculation:edit')")
    @Log(title = "成本核算", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpCostCalculation erpCostCalculation)
    {
        return toAjax(erpCostCalculationService.updateErpCostCalculation(erpCostCalculation));
    }

    /**
     * 删除成本核算
     */
    @PreAuthorize("@ss.hasPermi('calculation:calculation:remove')")
    @Log(title = "成本核算", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workOrders}")
    public AjaxResult remove(@PathVariable String[] workOrders)
    {
        return toAjax(erpCostCalculationService.deleteErpCostCalculationByWorkOrders(workOrders));
    }
}
